package gclib.entities;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.swing.JOptionPane;

/**
 * As this does not directly relate to any item in the Dungeons and Dragons world, it does reference the core elements of the game.
 * For example, Powers have many types of effects: Hit, Miss, Effect, Special, just to name a few. This class allows the object oriented
 * world to decyper the text description and utilize them.<br>
 * The "Daring Charge" Barbarian Attack comes from PHB 2 and will be used as an example of Effects. This Power would have 2 effects.
 * Coincedentally, each have conditionals for the effect to take place.
 *
 * The first is a <i>Special</i> effect. Here is the text:
 * <pre>
 * When charging, you can use this power in place
 * of a melee basic attack. If you charge, you gain
 * a +2 bonus to the attack roll and the damage
 * roll for each opportunity attack made against
 * you while you charge.
 * </pre>
 *
 * <p>From this text we decyper that there are two attributes that we are modifying: BONUS_TO_ATTACK, BONUS_TO_DAMAGE.</p>
 * <p>The amount is equal to: <code>+2 * (opportunity attack made against you)</code></p>
 * <p>The condition for the effect to be active is: <code>while you charge</code></p>
 *
 * @author Jason
 */
public class Effect {

    /**
     * Duration key phrases
     * before the end of your next turn
     * (lasts )?until the end of your next turn
     * ongoing
     * (save ends)
     * (lasts )?until the end of the encounter
     * lasts until the target attacks
     * lasts until the end of the weapon wielder's next turn
     * lasts for [numeric] [units]
     * ends if the target makes an attack
     * remain until
     */
    private Duration duration;
    /** This is one possibility to solve the issue from the example. */
    private Map<String, Integer> effectMap;
    private Map<String, String> questionEffectMap = new HashMap<String, String>();
    private Map<String, String> effectCalculationMap = new HashMap<String, String>();
    private String effectedStat;
    private Object value;
    private Map<String, Object> questions;//this would be a way of getting user input
    private Set<Condition> conditions;

    public void setQuestions(String[] questions) {
        if (questions == null) {
            this.questions = new HashMap<String, Object>();
        }
        for (String question : questions) {
            this.questions.put(question, null);
        }
    }

    public void askQuestions() {
        for (Entry<String, Object> entry : questions.entrySet()) {
            entry.setValue(JOptionPane.showInputDialog(entry.getKey()));
        }
    }

    public Set<Condition> getConditions() {
        if (conditions == null) {
            conditions = new HashSet<Condition>();//Collections.emptySet();
        }
        return conditions;
    }

    public void setConditions(Set<Condition> conditions) {
        this.conditions = conditions;
    }

    public Map<String, Integer> getEffectMap() {
        if(effectMap == null)
            effectMap = new HashMap<String, Integer>();
        return effectMap;
    }

    public void setEffectMap(Map<String, Integer> effectMap) {
        this.effectMap = effectMap;
    }

    public String getEffectedStat() {
        return effectedStat;
    }

    public void setEffectedStat(String effectedStat) {
        this.effectedStat = effectedStat;
    }

    public Map<String, Object> getQuestions() {
        if(questions==null)
            questions = new HashMap<String, Object>();
        return questions;
    }

    public void setQuestions(Map<String, Object> questions) {
        this.questions = questions;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }
}
